﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using SedionFormDesigner.Infrastructure;

namespace SedionFormDesigner.Service
{
    /// <summary>
    ///  用来给组件添加过滤
    ///  事件,属性,特性
    /// </summary>
    public class SedionTypeDescriptorFilterService : ITypeDescriptorFilterService
    {
        private IDesignerHost host;

        public SedionTypeDescriptorFilterService(IDesignerHost host)
        {
            this.host = host;
        }

        private IDesignerFilter GetDesignerFilter(IComponent component)
        {
            return host.GetDesigner(component) as IDesignerFilter;
        }

        #region ITypeDescriptorFilterService 成员

        /// <summary>
        ///  让给予的组件去过滤特性
        /// </summary>
        public bool FilterAttributes(System.ComponentModel.IComponent component, System.Collections.IDictionary attributes)
        {
            IDesignerFilter filter = GetDesignerFilter(component);
            if (filter != null)
            {
                filter.PreFilterAttributes(attributes);
                filter.PostFilterProperties(attributes);
                return true;
            }
            return false;
        }

        /// <summary>
        ///  让给予的组件去过滤事件
        /// </summary>
        public bool FilterEvents(System.ComponentModel.IComponent component, System.Collections.IDictionary events)
        {
            IDesignerFilter filter = GetDesignerFilter(component);
            if (filter != null)
            {
                filter.PreFilterEvents(events);
                filter.PostFilterEvents(events);
                return true;
            }
            return false;
        }

        /// <summary>
        ///  让给予的组件去过滤属性
        /// </summary>
        public bool FilterProperties(System.ComponentModel.IComponent component, System.Collections.IDictionary properties)
        {
            IDesignerFilter filter = GetDesignerFilter(component);
            if (filter != null)
            {
                filter.PreFilterProperties(properties);
                filter.PostFilterProperties(properties);
                return true;
            }
            return false;
        }

        #endregion
    }
}
